from rest_framework import serializers
from users.models import User
#1用户序列话化器
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id','username','mobile','email','password']



    #给密码增加额外的约束选项，不进行返回
    extra_kwargs = {
        'password':{
            'write_only':True
        }
    }

    #１.重写create方法，密码加密
    def create(self,validated_data):
        return User.objects.create_user(**validated_data)